package com.java2_20;

import java.util.Arrays;
import java.util.Objects;

public class People implements Cloneable{
    private String name;
    private int age;
    private char sex;
    private int[] arr;
    public People(){

    }

    public People(String name, int age, char sex) {
        this.name = name;
        this.age = age;
        this.sex = sex;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public char getSex() {
        return sex;
    }

    public void setSex(char sex) {
        this.sex = sex;
    }

    @Override
    public String toString() {
        return name + " " + age + " " + sex;
    }

    //深克隆
    @Override
    protected Object clone() throws CloneNotSupportedException {
        int[] arr1 = this.arr;
        int[] arr2 = new int[arr1.length];
        for (int i = 0; i < arr1.length; i++) {
            arr2[i] = arr1[i];
        }
        People clone = (People) super.clone();
        clone.arr = arr2;
        return clone;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        People people = (People) o;
        return age == people.age && sex == people.sex && Objects.equals(name, people.name) && Arrays.equals(arr, people.arr);
    }

}
